|
Scripting and Your Application An introduction to scripting |
Introduction to Scripting
Your application provides a new, industry standard interface that allows you to write scripts using any COM-aware scripting language, such as JavaScript, Python or Visual Basic. These scripts can be embedded into an HTML document, which can then be loaded into the interface to execute commands. As well as running individual commands from scripts you can also run your existing macros which have long been a feature of Datamine systems.
HTML can be used to create simple or comprehensive graphical interfaces for scripts. This can be thought of as a replacement for the !SCREEN macro command, but is many times more powerful.
The easiest way to start to use this powerful facility is to record a script by activating theHomeribbon and selectingScripts | Jscript | Record Script from the menu bar. This creates a simple HTML documents with Execute and Help buttons which allow you to replay the sequence of commands you have recorded.
However you will want to do more than that. You will want to change the interface so that, for example, you can specify input and output file names; you may also want to specify field and parameter values; and then you can add extra buttons, radio buttons, text boxes, check boxes, and so on, in order to make your interface more flexible.
The following figure shows a typical recorded script in the Customization panel (in this case, of Studio OP but this control bar is similar in all Datamine products):.
Changing the interface is done by editing the HTML script. However as well as adding a text box or push button you also need to define the action or event that occurs when you enter data into the text box or click the button. This is done using JavaScript or VB Script. You can run both Database and Design Window commands from these scripts as well as carrying out the usual programming functions. You can also interface with other systems through scripting.
We have provided some useful JavaScript functions to simplify tasks such as running macros and setting up pick lists.
This tutorial takes you through all the steps from recording and replaying scripts to designing your own interface. The aim of the tutorial is not to teach you HTML and JavaScript. These are both third party languages and there are plenty of books and other resources that do this job very well indeed. This tutorial concentrates on the tools that are needed to create and manage HTML pages, macro and other files that are used. It will assist your understanding of the tutorial significantly if you are already familiar with the concepts and methods of JavaScript and HTML.
Experienced users will recognize that the availability of an industry-standard COM interface to all the commands opens up enormous possibilities for integrating a Datamine application into their company's overall IT system. Commands can now be accessed and executed remotely from just about any programming language or system, including Access Basic, Sybase PowerBuilder, Borland Delphi, Visual Basic or C++.
|
Note that all file paths that are referenced by your system cannot exceed 128 characters in length |
The Scripting Interface
Commands are saved with a very simple user interface. The button replays the saved commands, and the button displays this dialog. Using an interactive HTML and JavaScript editor, it is quite easy to replace this with a custom user interface, similar to the following:
The dialog is actually an HTML table, using HTML text, buttons, text boxes and other controls. The HTML is written so that when a button is pressed, a short section of JavaScript is executed to carry out some function, such as using the Project File browser, or running some commands.
The HTML code used to represent the above table is as follows:
<TABLE cellSpacing=0 cellPadding=10 align=left border=0>
<TBODY>
<TR>
<TD>
<TABLE
style="BORDER-RIGHT: 2px outset; BORDER-TOP: 2px outset; FONT-SIZE: 10pt; BORDER-LEFT: 2px outset; BORDER-BOTTOM: 2px outset; FONT-FAMILY: MS Sans Serif; BACKGROUND-COLOR: buttonface"
cellSpacing=0 cellPadding=5 align=left border=0>
<TBODY>
<TR>
<TD colSpan=3><B>Example scripted dialog interface</B>
<HR>
</TD></TR>
<TR>
<TD>Input file</TD>
<TD><INPUT name=tbInput></TD>
<TD><INPUT language=javascript style="WIDTH: 30px" onclick="return btnBrowse1_onclick()" type=button value=... name=btnBrowse1></TD></TR>
<TR>
<TD>Output file</TD>
<TD><INPUT name=tbOutput></TD>
<TD><INPUT language=javascript style="WIDTH: 30px" onclick="return btnBrowse2_onclick()" type=button value=... name=btnBrowse2></TD></TR>
<TR>
<TD align=middle colSpan=3><INPUT language=javascript style="WIDTH: 75px" onclick="return btnOK_onclick()" type=button value=OK name=btnOK></TD></TR></TBODY></TABLE>
<P> </P></TD></TR></TBODY></TABLE>
The JavaScript code used to activate this dialog is greatly simplified by using the Datamine basic Script Library Component (SLC). The JavaScript code to initialize the SLC is already included in the auto-saved file, and is similar to the following:
<SCRIPT language=javascript id=clientEventHandlersJS>
<!--
var dm = null;
function window_onload() {
if (typeof(top.DCM) != 'object' || top.DCM == null)
top.DCM = new ActiveXObject('DMComServer.DMCommandManager');
dm=top.DCM;
if (typeof(top.dmBrowser) != 'object' || top.dmBrowser == null)
dmBrowser = new ActiveXObject('DMBrowserCtl.DMBrowserCtl');
top.dmBrowser.connect("name=");
var commonDir = window.dialogArguments;
// commonDir="d:/program files/datamine/dmstudio.140/scripts/common";
// document.body.style.backgroundImage = "url(" + commonDir + "/images/background.gif)";
document.images("logo").src = commonDir + "/images/dmlogo200x93.gif";
var cell = document.all("clear")
// for (var i = 0; i < cell.length; i++)
// cell[i].style.backgroundImage = "url(" + commonDir + "/images/background.gif)";
}
function window_onunload() {
dm = null;
dmBrowser = null;
}
function btnBrowse1_onclick() {
top.dmBrowser.popup();
tbInput.value = top.dmBrowser.selectedTable;
}
function btnBrowse2_onclick() {
top.dmBrowser.Popup();
tbOutput.value = top.dmBrowser.selectedTable;
}
function btnOK_onclick() {
alert("This button can execute the\ncommands that you have recorded");
}
function btnClose_onclick() {
window.close();
}
//-->
</SCRIPT>
Then, to add JavaScript functionality to use the Project File browser to prompt for the name of the input file, and then a snippet to write that name into the text box can be as easy as:
tbInput.value = dm.browseForFile();
-
For more information on Scripting in your application, and some useful exercises, see your Scripting Tutorial, available from the Help menu.
-
Datamine also offers comprehensive training courses that will teach you how to use scripting to get the best out of your system. Contact your Datamine Support Representative for more information.